<!Doctype html>
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
	<meta name="viewport" content="width=device-width, initial-scale=1.0" />
	<title>C 函数 | 菜鸟教程</title>

  <meta name='robots' content='max-image-preview:large' />
<link rel='stylesheet' id='classic-theme-styles-css' href='../0/classic-themes.min.css?ver=6.2' type='text/css' media='all' />
<link rel="canonical" href="../cprogramming/c-functions.html" />
<meta name="keywords" content="C 函数">
<meta name="description" content="C 函数   函数是一组一起执行一个任务的语句。每个 C 程序都至少有一个函数，即主函数 main() ，所有简单的程序都可以定义其他额外的函数。 您可以把代码划分到不同的函数中。如何划分代码到不同的函数中是由您来决定的，但在逻辑上，划分通常是根据每个函数执行一个特定的任务来进行的。 函数声明告诉编译器函数的名称、返回类型和参数。函数定义提供了函数的实际主体。 C 标准库提供了大量的程序可以调用的内置函数。例如，函数 strcat() ..">
		
	<link rel="shortcut icon" href="https://static.runoob.com/images/favicon.ico">
	<link rel="stylesheet" href="../0/style.css?v=1.170" type="text/css" media="all" />	
	<link rel="stylesheet" href="../0/font-awesome.min.css" media="all" />	
  <!--[if gte IE 9]><!-->
  <script src=""></script>
  <!--<![endif]-->
  <!--[if lt IE 9]>
     <script src=""></script>
     <script src=""></script>
  <![endif]-->
  <link rel="apple-touch-icon" href="https://static.runoob.com/images/icon/mobile-icon.png"/>
  <meta name="apple-mobile-web-app-title" content="菜鸟教程">
</head>
<body>

<!--  头部 -->
<div class="container logo-search">

  <div class="col search row-search-mobile">
    <form action="index.php">
      <input class="placeholder" placeholder="搜索……" name="s" autocomplete="off">
      
    </form>
  </div>

  <div class="row">
    <div class="col logo">
      <h1><a href="../">菜鸟教程 -- 学的不仅是技术，更是梦想！</a></h1>
    </div>
        <div class="col right-list"> 
    <button class="btn btn-responsive-nav btn-inverse" data-toggle="collapse" data-target=".nav-main-collapse" id="pull" style=""> <i class="fa fa-navicon"></i> </button>
    </div>
        
    <div class="col search search-desktop last">
      <div class="search-input" >
      <form action="//www.runoob.com/" target="_blank">
        <input class="placeholder" id="s" name="s" placeholder="搜索……"  autocomplete="off" style="height: 44px;">
      </form>
      
      </div>
    </div>
  </div>
</div>



<!-- 导航栏 -->
<!-- 导航栏 -->
<div class="container navigation">
	<div class="row">
		<div class="col nav">
			<ul class="pc-nav" id="runoob-detail-nav">
				<li><a href="../">首页</a></li>
				<li><a href="../html/html-tutorial.html">HTML</a></li>
				<li><a href="../css/css-tutorial.html">CSS</a></li>
				<li><a href="../js/js-tutorial.html">JavaScript</a></li>
				<li><a href="javascript:void(0);" data-id="vue">Vue</a></li>
				<li><a href="javascript:void(0);" data-id="bootstrap">Bootstrap</a></li>
				<li><a href="../nodejs/nodejs-tutorial.html">NodeJS</a></li>
				<li><a href="../python3/python3-tutorial.html">Python3</a></li>
				<li><a href="../python/python-tutorial.html">Python2</a></li>
				<li><a href="../java/java-tutorial.html">Java</a></li>
				<li><a href="../cprogramming/c-tutorial.html">C</a></li>
				<li><a href="../cplusplus/cpp-tutorial.html">C++</a></li>
				<li><a href="../csharp/csharp-tutorial.html">C#</a></li>
				<li><a href="../go/go-tutorial.html">Go</a></li>
				<li><a href="../sql/sql-tutorial.html">SQL</a></li>
				<li><a href="../linux/linux-tutorial.html">Linux</a></li>
				<li><a href="../jquery/jquery-tutorial.html">jQuery</a></li>
				<li><a href="../browser-history">本地书签</a></li>
				<!--
			
				<li><a href="../w3cnote/knowledge-start.html" style="font-weight: bold;" onclick="_hmt.push(['_trackEvent', '星球', 'click', 'start'])" title="我的圈子">我的圈子</a></li>				
				<li><a href="javascript:;" class="runoob-pop">登录</a></li>
				-->
      		</ul>
			<ul class="mobile-nav">
				<li><a href="../">首页</a></li>
				<li><a href="../html/html-tutorial.html">HTML</a></li>
				<li><a href="../css/css-tutorial.html">CSS</a></li>
				<li><a href="../js/js-tutorial.html">JS</a></li>
				<li><a href="../browser-history">本地书签</a></li>
				<li><a href="javascript:void(0)" class="search-reveal">Search</a> </li>
			</ul>
			
		</div>
	</div>
</div>

<div class="container sub-navigation sub-navigation-articles" style="display:none">
	<div class="row">
		<div class="col nav-sub">
		<ul id="python">
			<li class="cat-item"><a href="../python3/python3-tutorial.html">Python3 教程 <i class="fa fa-external-link" aria-hidden="true"></i></a></li>
			<li class="cat-item"><a href="../python/python-tutorial.html">Python2 教程 <i class="fa fa-external-link" aria-hidden="true"></i></a></li>
		</ul>
		<ul id="vue">
			<li class="cat-item"><a href="../vue3/vue3-tutorial.html">Vue3 教程 <i class="fa fa-external-link" aria-hidden="true"></i></a></li>
			<li class="cat-item"><a href="../vue/vue-tutorial.html">vue2 教程 <i class="fa fa-external-link" aria-hidden="true"></i></a></li>
		</ul>

		<ul id="bootstrap">
			<li class="cat-item"><a href="../bootstrap/bootstrap-tutorial.html">Bootstrap3 教程 <i class="fa fa-external-link" aria-hidden="true"></i></a></li>
			<li class="cat-item"><a href="../bootstrap4/bootstrap4-tutorial.html">Bootstrap4 教程 <i class="fa fa-external-link" aria-hidden="true"></i></a></li>
			<li class="cat-item"><a href="../bootstrap5/bootstrap5-tutorial.html">Bootstrap5 教程 <i class="fa fa-external-link" aria-hidden="true"></i></a></li>
			<li class="cat-item"><a href="../bootstrap/bootstrap-v2-tutorial.html">Bootstrap2 教程 <i class="fa fa-external-link" aria-hidden="true"></i></a></li>
		</ul>
		</div>
	</div>
</div><!--  内容  -->
<div class="container main">
	<!-- 中间 -->
	<div class="row">
	
<div class="runoob-col-md2">
<div class="left-column">
	<div class="tab" style="overflow: hidden;text-overflow: ellipsis;white-space: nowrap;">
	<i class="fa fa-list" aria-hidden="true"></i> 
	<span>C 教程</span>
	<a data-cate="157" href="javascript:void(0);" title="夜间模式"  id="moon"><i class="fa fa-moon-o" aria-hidden="true" style="line-height: 28px;font-size: 1.2em;margin: 2px 4px 0;"></i></a>
	<a data-cate="157" style="display:none;" href="javascript:void(0);" title="日间模式"  id="sun" ><i class="fa fa-sun-o" aria-hidden="true" style="line-height: 28px;font-size: 1.2em;margin: 2px 4px 0;line-height: 28px;
}"></i></a>

	</div>
	<div class="sidebar-box gallery-list">
		<div class="design" id="leftcolumn">
						<a target="_top" title="C 语言教程"  href="../cprogramming/c-tutorial.html" >
			C 语言教程			</a>
						<a target="_top" title="C 简介"  href="../cprogramming/c-intro.html" >
			C 简介			</a>
						<a target="_top" title="C 环境设置"  href="../cprogramming/c-environment-setup.html" >
			C 环境设置			</a>
						<a target="_top" title="C 程序结构"  href="../cprogramming/c-program-structure.html" >
			C 程序结构			</a>
						<a target="_top" title="C 基本语法"  href="../cprogramming/c-basic-syntax.html" >
			C 基本语法			</a>
						<a target="_top" title="C 数据类型"  href="../cprogramming/c-data-types.html" >
			C 数据类型			</a>
						<a target="_top" title="C 变量"  href="../cprogramming/c-variables.html" >
			C 变量			</a>
						<a target="_top" title="C 常量"  href="../cprogramming/c-constants.html" >
			C 常量			</a>
						<a target="_top" title="C 存储类"  href="../cprogramming/c-storage-classes.html" >
			C 存储类			</a>
						<a target="_top" title="C 运算符"  href="../cprogramming/c-operators.html" >
			C 运算符			</a>
						<a target="_top" title="C 判断"  href="../cprogramming/c-decision.html" >
			C 判断			</a>
						<a target="_top" title="C 循环"  href="../cprogramming/c-loops.html" >
			C 循环			</a>
						<a target="_top" title="C 函数"  href="../cprogramming/c-functions.html" >
			C 函数			</a>
						<a target="_top" title="C 作用域规则"  href="../cprogramming/c-scope-rules.html" >
			C 作用域规则			</a>
						<a target="_top" title="C 数组"  href="../cprogramming/c-arrays.html" >
			C 数组			</a>
			<a target="_top" title="C enum(枚举)" href="../cprogramming/c-enum.html">C enum(枚举)</a>			<a target="_top" title="C 指针"  href="../cprogramming/c-pointers.html" >
			C 指针			</a>
			<a target="_top" title="C 函数指针与回调函数" href="../cprogramming/c-fun-pointer-callback.html">C 函数指针与回调函数</a>			<a target="_top" title="C 字符串"  href="../cprogramming/c-strings.html" >
			C 字符串			</a>
						<a target="_top" title="C 结构体"  href="../cprogramming/c-structures.html" >
			C 结构体			</a>
						<a target="_top" title="C 共用体"  href="../cprogramming/c-unions.html" >
			C 共用体			</a>
						<a target="_top" title="C 位域"  href="../cprogramming/c-bit-fields.html" >
			C 位域			</a>
						<a target="_top" title="C typedef"  href="../cprogramming/c-typedef.html" >
			C typedef			</a>
						<a target="_top" title="C 输入 &#038; 输出"  href="../cprogramming/c-input-output.html" >
			C 输入 & 输出			</a>
						<a target="_top" title="C 文件读写"  href="../cprogramming/c-file-io.html" >
			C 文件读写			</a>
						<a target="_top" title="C 预处理器"  href="../cprogramming/c-preprocessors.html" >
			C 预处理器			</a>
						<a target="_top" title="C 头文件"  href="../cprogramming/c-header-files.html" >
			C 头文件			</a>
						<a target="_top" title="C 强制类型转换"  href="../cprogramming/c-type-casting.html" >
			C 强制类型转换			</a>
						<a target="_top" title="C 错误处理"  href="../cprogramming/c-error-handling.html" >
			C 错误处理			</a>
						<a target="_top" title="C 递归"  href="../cprogramming/c-recursion.html" >
			C 递归			</a>
						<a target="_top" title="C 可变参数"  href="../cprogramming/c-variable-arguments.html" >
			C 可变参数			</a>
						<a target="_top" title="C 内存管理"  href="../cprogramming/c-memory-management.html" >
			C 内存管理			</a>
						<a target="_top" title="C 命令行参数"  href="../cprogramming/c-command-line-arguments.html" >
			C 命令行参数			</a>
			
<a target="_top" title="C 排序算法" href="../cprogramming/c-sort-algorithm.html">C 排序算法</a>
<a target="_top" title="C 语言实例" href="../cprogramming/c-examples.html">C 语言实例 </a>
<a target="_top" title="C 语言经典100例" href="../cprogramming/c-100-examples.html"> C 经典100例 </a>
<br><h2 class="left">C <span class="left_h2">标准库</span></h2>			<a target="_top" title="C 标准库 &#8211; 参考手册"  href="../cprogramming/c-standard-library.html" >
			C 标准库 - 参考手册			</a>
						<a target="_top" title="C 标准库 &#8211; &lt;assert.h&gt;"  href="../cprogramming/c-standard-library-assert-h.html" >
			C 标准库 - &lt;assert.h&gt;			</a>
						<a target="_top" title="C 标准库 &#8211; &lt;ctype.h&gt;"  href="../cprogramming/c-standard-library-ctype-h.html" >
			C 标准库 - &lt;ctype.h&gt;			</a>
						<a target="_top" title="C 标准库 &#8211; &lt;errno.h&gt;"  href="../cprogramming/c-standard-library-errno-h.html" >
			C 标准库 - &lt;errno.h&gt;			</a>
						<a target="_top" title="C 标准库 &#8211; &lt;float.h&gt;"  href="../cprogramming/c-standard-library-float-h.html" >
			C 标准库 - &lt;float.h&gt;			</a>
						<a target="_top" title="C 标准库 &#8211; &lt;limits.h&gt;"  href="../cprogramming/c-standard-library-limits-h.html" >
			C 标准库 - &lt;limits.h&gt;			</a>
						<a target="_top" title="C 标准库 &#8211; &lt;locale.h&gt;"  href="../cprogramming/c-standard-library-locale-h.html" >
			C 标准库 - &lt;locale.h&gt;			</a>
						<a target="_top" title="C 标准库 &#8211; &lt;math.h&gt;"  href="../cprogramming/c-standard-library-math-h.html" >
			C 标准库 - &lt;math.h&gt;			</a>
						<a target="_top" title="C 标准库 &#8211; &lt;setjmp.h&gt;"  href="../cprogramming/c-standard-library-setjmp-h.html" >
			C 标准库 - &lt;setjmp.h&gt;			</a>
						<a target="_top" title="C 标准库 &#8211; &lt;signal.h&gt;"  href="../cprogramming/c-standard-library-signal-h.html" >
			C 标准库 - &lt;signal.h&gt;			</a>
						<a target="_top" title="C 标准库 &#8211; &lt;stdarg.h&gt;"  href="../cprogramming/c-standard-library-stdarg-h.html" >
			C 标准库 - &lt;stdarg.h&gt;			</a>
						<a target="_top" title="C 标准库 &#8211; &lt;stddef.h&gt;"  href="../cprogramming/c-standard-library-stddef-h.html" >
			C 标准库 - &lt;stddef.h&gt;			</a>
						<a target="_top" title="C 标准库 &#8211; &lt;stdio.h&gt;"  href="../cprogramming/c-standard-library-stdio-h.html" >
			C 标准库 - &lt;stdio.h&gt;			</a>
						<a target="_top" title="C 标准库 &#8211; &lt;stdlib.h&gt;"  href="../cprogramming/c-standard-library-stdlib-h.html" >
			C 标准库 - &lt;stdlib.h&gt;			</a>
						<a target="_top" title="C 标准库 &#8211; &lt;string.h&gt;"  href="../cprogramming/c-standard-library-string-h.html" >
			C 标准库 - &lt;string.h&gt;			</a>
						<a target="_top" title="C 标准库 &#8211; &lt;time.h&gt;"  href="../cprogramming/c-standard-library-time-h.html" >
			C 标准库 - &lt;time.h&gt;			</a>
						<a target="_top" title="C 语言测验"  href="../cprogramming/c-quiz.html" >
			C 语言测验			</a>
				
		</div>
	</div>	
</div>
</div>	<div class="col middle-column">
		
	
	<div class="article">
		
		<div class="previous-next-links">
			<div class="previous-design-link"><i style="font-size:16px;" class="fa fa-arrow-left" aria-hidden="true"></i> <a href="../cprogramming/c-loops.html" rel="prev"> C 循环</a> </div>
			<div class="next-design-link"><a href="../cprogramming/c-scope-rules.html" rel="next"> C 作用域规则</a> <i style="font-size:16px;" class="fa fa-arrow-right" aria-hidden="true"></i></div>
		</div>
<div class="article-heading-ad" style="display: block;">
<script async src=""
     crossorigin="anonymous"></script>
<!-- 728*90 固定 -->
<ins class="adsbygoogle"
     style="display:inline-block;width:728px;height:90px"
     data-ad-client="ca-pub-5751451760833794"
     data-ad-slot="2147566827"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script>
		</div>
		<div class="article-body">
		
			<div class="article-intro" id="content">
			
			
<h1>C <span class="color_h1">函数</span></h1>

<div class="tutintro">
<p>函数是一组一起执行一个任务的语句。每个 C 程序都至少有一个函数，即主函数 <b>main()</b> ，所有简单的程序都可以定义其他额外的函数。</p>
<p>您可以把代码划分到不同的函数中。如何划分代码到不同的函数中是由您来决定的，但在逻辑上，划分通常是根据每个函数执行一个特定的任务来进行的。</p>
<p>函数<b>声明</b>告诉编译器函数的名称、返回类型和参数。函数<b>定义</b>提供了函数的实际主体。</p>
<p>C 标准库提供了大量的程序可以调用的内置函数。例如，函数 <b>strcat()</b> 用来连接两个字符串，函数 <b>memcpy()</b> 用来复制内存到另一个位置。</p>
<p>函数还有很多叫法，比如方法、子例程或程序，等等。</p>
</div>

<h2 class="tutheader">定义函数</h2>
<p>C 语言中的函数定义的一般形式如下：</p>
<pre>
return_type function_name( parameter list )
{
   body of the function
}
</pre>
<p>在 C 语言中，函数由一个函数头和一个函数主体组成。下面列出一个函数的所有组成部分：</p>
<ul class="list">
<li><b>返回类型：</b>一个函数可以返回一个值。<b>return_type</b> 是函数返回的值的数据类型。有些函数执行所需的操作而不返回值，在这种情况下，return_type 是关键字 <b>void</b>。</li>
<li><b>函数名称：</b>这是函数的实际名称。函数名和参数列表一起构成了函数签名。</li>
<li><b>参数：</b>参数就像是占位符。当函数被调用时，您向参数传递一个值，这个值被称为实际参数。参数列表包括函数参数的类型、顺序、数量。参数是可选的，也就是说，函数可能不包含参数。</li>
<li><b>函数主体：</b>函数主体包含一组定义函数执行任务的语句。</li>
</ul>

<h2 class="tutheader">实例</h2>
<p>以下是 <b>max()</b> 函数的源代码。该函数有两个参数 num1 和 num2，会返回这两个数中较大的那个数：</p>
<div class="example">
<div class="example_code">
<div class="hl-main"><span class="hl-mlcomment">/*</span><span class="hl-mlcomment"> 函数返回两个数中较大的那个数 </span><span class="hl-mlcomment">*/</span><span class="hl-code">
</span><span class="hl-types">int</span><span class="hl-code"> </span><span class="hl-identifier">max</span><span class="hl-brackets">(</span><span class="hl-types">int</span><span class="hl-code"> </span><span class="hl-identifier">num1</span><span class="hl-code">, </span><span class="hl-types">int</span><span class="hl-code"> </span><span class="hl-identifier">num2</span><span class="hl-brackets">)</span><span class="hl-code"> 
</span><span class="hl-brackets">{</span><span class="hl-code">
   </span><span class="hl-mlcomment">/*</span><span class="hl-mlcomment"> 局部变量声明 </span><span class="hl-mlcomment">*/</span><span class="hl-code">
   </span><span class="hl-types">int</span><span class="hl-code"> </span><span class="hl-identifier">result</span><span class="hl-code">;
 
   </span><span class="hl-reserved">if</span><span class="hl-code"> </span><span class="hl-brackets">(</span><span class="hl-identifier">num1</span><span class="hl-code"> &gt; </span><span class="hl-identifier">num2</span><span class="hl-brackets">)</span><span class="hl-code"> </span><span class="hl-brackets">{</span><span class="hl-code">
      </span><span class="hl-identifier">result</span><span class="hl-code"> = </span><span class="hl-identifier">num1</span><span class="hl-code">;
   </span><span class="hl-brackets">}</span><span class="hl-code"> </span><span class="hl-reserved">else</span><span class="hl-code"> </span><span class="hl-brackets">{</span><span class="hl-code">
      </span><span class="hl-identifier">result</span><span class="hl-code"> = </span><span class="hl-identifier">num2</span><span class="hl-code">;
   </span><span class="hl-brackets">}</span><span class="hl-code">
   </span><span class="hl-reserved">return</span><span class="hl-code"> </span><span class="hl-identifier">result</span><span class="hl-code">; 
</span><span class="hl-brackets">}</span></div>
</div>
</div>

<h2 class="tutheader">函数声明</h2>
<p>函数<b>声明</b>会告诉编译器函数名称及如何调用函数。函数的实际主体可以单独定义。</p>
<p>函数声明包括以下几个部分：</p>
<pre>
return_type function_name( parameter list );
</pre>
<p>针对上面定义的函数 max()，以下是函数声明：</p>
<pre>
int max(int num1, int num2);
</pre>
<p>在函数声明中，参数的名称并不重要，只有参数的类型是必需的，因此下面也是有效的声明：</p>
<pre>
int max(int, int);
</pre>
<p>当您在一个源文件中定义函数且在另一个文件中调用函数时，函数声明是必需的。在这种情况下，您应该在调用函数的文件顶部声明函数。</p>

<h2 class="tutheader">调用函数</h2>
<p>创建 C 函数时，会定义函数做什么，然后通过调用函数来完成已定义的任务。</p>
<p>当程序调用函数时，程序控制权会转移给被调用的函数。被调用的函数执行已定义的任务，当函数的返回语句被执行时，或到达函数的结束括号时，会把程序控制权交还给主程序。</p>
<p>调用函数时，传递所需参数，如果函数返回一个值，则可以存储返回值。例如：</p>
<div class="example">
<h2 class="example">实例</h2>
<div class="example_code">
<div class="hl-main"><span class="hl-prepro">#include</span><span class="hl-prepro"> </span><span class="hl-quotes">&lt;</span><span class="hl-string">stdio.h</span><span class="hl-quotes">&gt;</span><span class="hl-prepro"></span><span class="hl-code">
 
</span><span class="hl-mlcomment">/*</span><span class="hl-mlcomment"> 函数声明 </span><span class="hl-mlcomment">*/</span><span class="hl-code">
</span><span class="hl-types">int</span><span class="hl-code"> </span><span class="hl-identifier">max</span><span class="hl-brackets">(</span><span class="hl-types">int</span><span class="hl-code"> </span><span class="hl-identifier">num1</span><span class="hl-code">, </span><span class="hl-types">int</span><span class="hl-code"> </span><span class="hl-identifier">num2</span><span class="hl-brackets">)</span><span class="hl-code">;
 
</span><span class="hl-types">int</span><span class="hl-code"> </span><span class="hl-identifier">main</span><span class="hl-code"> </span><span class="hl-brackets">(</span><span class="hl-brackets">)</span><span class="hl-code">
</span><span class="hl-brackets">{</span><span class="hl-code">
   </span><span class="hl-mlcomment">/*</span><span class="hl-mlcomment"> 局部变量定义 </span><span class="hl-mlcomment">*/</span><span class="hl-code">
   </span><span class="hl-types">int</span><span class="hl-code"> </span><span class="hl-identifier">a</span><span class="hl-code"> = </span><span class="hl-number">100</span><span class="hl-code">;
   </span><span class="hl-types">int</span><span class="hl-code"> </span><span class="hl-identifier">b</span><span class="hl-code"> = </span><span class="hl-number">200</span><span class="hl-code">;
   </span><span class="hl-types">int</span><span class="hl-code"> </span><span class="hl-identifier">ret</span><span class="hl-code">;
 
   </span><span class="hl-mlcomment">/*</span><span class="hl-mlcomment"> 调用函数来获取最大值 </span><span class="hl-mlcomment">*/</span><span class="hl-code">
   </span><span class="hl-identifier">ret</span><span class="hl-code"> = </span><span class="hl-identifier">max</span><span class="hl-brackets">(</span><span class="hl-identifier">a</span><span class="hl-code">, </span><span class="hl-identifier">b</span><span class="hl-brackets">)</span><span class="hl-code">;
 
   </span><span class="hl-identifier">printf</span><span class="hl-brackets">(</span><span class="hl-code"> </span><span class="hl-quotes">&quot;</span><span class="hl-string">Max value is : %d</span><span class="hl-special">\</span><span class="hl-string">n</span><span class="hl-quotes">&quot;</span><span class="hl-code">, </span><span class="hl-identifier">ret</span><span class="hl-code"> </span><span class="hl-brackets">)</span><span class="hl-code">;
 
   </span><span class="hl-reserved">return</span><span class="hl-code"> </span><span class="hl-number">0</span><span class="hl-code">;
</span><span class="hl-brackets">}</span><span class="hl-code">
 
</span><span class="hl-mlcomment">/*</span><span class="hl-mlcomment"> 函数返回两个数中较大的那个数 </span><span class="hl-mlcomment">*/</span><span class="hl-code">
</span><span class="hl-types">int</span><span class="hl-code"> </span><span class="hl-identifier">max</span><span class="hl-brackets">(</span><span class="hl-types">int</span><span class="hl-code"> </span><span class="hl-identifier">num1</span><span class="hl-code">, </span><span class="hl-types">int</span><span class="hl-code"> </span><span class="hl-identifier">num2</span><span class="hl-brackets">)</span><span class="hl-code"> 
</span><span class="hl-brackets">{</span><span class="hl-code">
   </span><span class="hl-mlcomment">/*</span><span class="hl-mlcomment"> 局部变量声明 </span><span class="hl-mlcomment">*/</span><span class="hl-code">
   </span><span class="hl-types">int</span><span class="hl-code"> </span><span class="hl-identifier">result</span><span class="hl-code">;
 
   </span><span class="hl-reserved">if</span><span class="hl-code"> </span><span class="hl-brackets">(</span><span class="hl-identifier">num1</span><span class="hl-code"> &gt; </span><span class="hl-identifier">num2</span><span class="hl-brackets">)</span><span class="hl-code">
      </span><span class="hl-identifier">result</span><span class="hl-code"> = </span><span class="hl-identifier">num1</span><span class="hl-code">;
   </span><span class="hl-reserved">else</span><span class="hl-code">
      </span><span class="hl-identifier">result</span><span class="hl-code"> = </span><span class="hl-identifier">num2</span><span class="hl-code">;
 
   </span><span class="hl-reserved">return</span><span class="hl-code"> </span><span class="hl-identifier">result</span><span class="hl-code">; 
</span><span class="hl-brackets">}</span></div>
</div>
</div>
<p>把 max() 函数和 main() 函数放一块，编译源代码。当运行最后的可执行文件时，会产生下列结果：</p>
<pre>
Max value is : 200
</pre>

<h2 class="tutheader">函数参数</h2>
<p>如果函数要使用参数，则必须声明接受参数值的变量。这些变量称为函数的<b>形式参数</b>。</p>
<p>形式参数就像函数内的其他局部变量，在进入函数时被创建，退出函数时被销毁。</p>
<p>当调用函数时，有两种向函数传递参数的方式：</p>
<table class="reference notranslate">
<tr><th style = "width:30%">调用类型</th><th>描述</th></tr>
<tr><td> <a href="../cprogramming/c-function-call-by-value.html" title="C 中传值方式调用函数">传值调用</a></td><td>该方法把参数的实际值复制给函数的形式参数。在这种情况下，修改函数内的形式参数不会影响实际参数。</td> </tr>



<tr><td> <a href="../cprogramming/c-function-call-by-pointer.html" title="C 中引用方式调用函数">引用调用</a></td><td>通过指针传递方式，形参为指向实参地址的指针，当对形参的指向操作时，就相当于对实参本身进行的操作。</td> </tr>
</table>
<p>默认情况下，C 使用<b>传值调用</b>来传递参数。一般来说，这意味着函数内的代码不能改变用于调用函数的实际参数。</p>			<!-- 其他扩展 -->
						
			</div>
			
		</div>
		
		<div class="previous-next-links">
			<div class="previous-design-link"><i style="font-size:16px;" class="fa fa-arrow-left" aria-hidden="true"></i> <a href="../cprogramming/c-loops.html" rel="prev"> C 循环</a> </div>
			<div class="next-design-link"><a href="../cprogramming/c-scope-rules.html" rel="next"> C 作用域规则</a> <i style="font-size:16px;" class="fa fa-arrow-right" aria-hidden="true"></i></div>
		</div>
		<!-- 笔记列表 -->
		<style>
.wrapper {
  /*text-transform: uppercase; */
  background: #ececec;
  color: #555;
  cursor: help;
  font-family: "Gill Sans", Impact, sans-serif;
  font-size: 20px;
  position: relative;
  text-align: center;
  width: 200px;
  -webkit-transform: translateZ(0); /* webkit flicker fix */
  -webkit-font-smoothing: antialiased; /* webkit text rendering fix */
}

.wrapper .tooltip {
  white-space: nowrap;
  font-size: 14px;
  text-align: left;
  background: #96b97d;
  bottom: 100%;
  color: #fff;
  display: block;
  left: -25px;
  margin-bottom: 15px;
  opacity: 0;
  padding: 14px;
  pointer-events: none;
  position: absolute;
  
  -webkit-transform: translateY(10px);
     -moz-transform: translateY(10px);
      -ms-transform: translateY(10px);
       -o-transform: translateY(10px);
          transform: translateY(10px);
  -webkit-transition: all .25s ease-out;
     -moz-transition: all .25s ease-out;
      -ms-transition: all .25s ease-out;
       -o-transition: all .25s ease-out;
          transition: all .25s ease-out;
  -webkit-box-shadow: 2px 2px 6px rgba(0, 0, 0, 0.28);
     -moz-box-shadow: 2px 2px 6px rgba(0, 0, 0, 0.28);
      -ms-box-shadow: 2px 2px 6px rgba(0, 0, 0, 0.28);
       -o-box-shadow: 2px 2px 6px rgba(0, 0, 0, 0.28);
          box-shadow: 2px 2px 6px rgba(0, 0, 0, 0.28);
}
.tooltip a {
	color:#fff;
}
/* This bridges the gap so you can mouse into the tooltip without it disappearing */
.wrapper .tooltip:before {
  bottom: -20px;
  content: " ";
  display: block;
  height: 20px;
  left: 0;
  position: absolute;
  width: 100%;
}  

/* CSS Triangles - see Trevor's post */
.wrapper .tooltip:after {
  border-left: solid transparent 10px;
  border-right: solid transparent 10px;
  border-top: solid #96b97d 10px;
  bottom: -10px;
  content: " ";
  height: 0;
  left: 20%;
  margin-left: -13px;
  position: absolute;
  width: 0;
}
.wrapper .tooltip1 {
	margin-left: 50px;
	padding-top: 0px;
}
/*
.wrapper:hover .tooltip {
  opacity: 1;
  pointer-events: auto;
  -webkit-transform: translateY(0px);
     -moz-transform: translateY(0px);
      -ms-transform: translateY(0px);
       -o-transform: translateY(0px);
          transform: translateY(0px);
}
*/
/* IE can just show/hide with no transition */
.lte8 .wrapper .tooltip {
  display: none;
}

.lte8 .wrapper:hover .tooltip {
  display: block;
}

</style>

<link rel="stylesheet" href="../0/upvotejs.css">
<script src=""></script>
<script src=""></script>
<div class="title" id="comments">
	<h2 class="">
    <div class="altblock">
				<i style="font-size:28px;margin-top: 8px;" class="fa fa-plus-square" aria-hidden="true"></i>
		    </div>
    <span class="mw-headline" id="qa_headline">15  篇笔记</span>
	<span class="mw-headline" id="user_add_note" style="float:right;line-height: 62px;padding-right: 14px;"><i class="fa fa-pencil-square-o" aria-hidden="true"></i>  写笔记</span>
    </h2>
</div>

<div id="postcomments"  style="display:none;" >
	<ol class="commentlist">
		<li class="comment even thread-even depth-1" id="comment-10248"><span class="comt-f">#0</span><div class="comt-avatar wrapper"><i style="font-size:36px;" class="fa fa-user-circle" aria-hidden="true"></i><div class="tooltip"><p><i class="fa fa-user" aria-hidden="true"></i>&nbsp;&nbsp;&nbsp;Sad</p><p><i class="fa fa-envelope" aria-hidden="true"></i>&nbsp;&nbsp;347***568@qq.com</p></div><div id="runoobvote-id-10248" data-commid = "10248" class="upvotejs"><a class="upvote"></a> <span class="count">305</span></div></div><div class="comt-main" id="div-comment-10248"><p>根据函数能否被其他源文件调用，将函数区分为内部函数和外部函数。
</p><h2>
内部函数
</h2><p>
如果一个函数只能被本文件中其他函数所调用，它称为内部函数。在定义内部函数时，在函数名和函数类型的前面加 static，即
</p><pre>
static 类型名 函数名 （形参表）
</pre><p>
例如，函数的首行：
</p><pre>
static int max(int a,int b)
</pre><p>
内部函数又称静态函数。使用内部函数，可以使函数的作用域只局限于所在文件。即使在不同的文件中有同名的内部函数，也互不干扰。提高了程序的可靠性。
</p><h2>
外部函数
</h2><p>
如果在定义函数时，在函数的首部的最左端加关键字 extern，则此函数是外部函数，可供其它文件调用。
</p><p>如函数首部可以为
</p><pre>
extern int max (int a,int b)
</pre><p>
C 语言规定，如果在定义函数时省略 extern，则默认为外部函数。
</p><p>
在需要调用此函数的其他文件中，需要对此函数作声明（不要忘记，即使在本文件中调用一个函数，也要用函数原型来声明）。在对此函数作声明时，要加关键字 extern，表示该函数是在其他文件中定义的外部函数。
</p>
<h2>实例
</h2>
<p>以下实例通过多个文件的函数实现输入一串字符串，然后删除指定的字符：</p>
<p>
file1.c(文件1)
</p><pre>
#include &lt;stdio.h&gt;

static void delete_string(char str[],char ch);
int main()
{
    extern void enter(char str[]); // 对函数的声明
    extern void print(char str[]); // 对函数的声明
    char c,str[100];
    enter(str);
    scanf("%c",&amp;c);
    delete_string(str,c);
    print(str);
    return 0;
}

static void delete_string(char str[],char ch)//内部函数
{
    int i,j;
    for(i=j=0;str[i]!='\0';i++)
    if(str[i]!=ch)
    str[j++]=str[i];
    str[j]='\0';
}
</pre>
<p>
file2.c(文件2)
</p><pre>
#include &lt;stdio.h&gt;

void enter(char str[100]) // 定义外部函数 enter
{
    fgets(str, 100, stdin); // 向字符数组输入字符串
}
</pre>
<p>
file3.c(文件3)
</p><pre>
#include &lt;stdio.h&gt;

void print(char str[]) // 定义外部函数 print
{
    printf("%s\n",str);
}
</pre><p>
输入字符串"abcdef"，给字符数组 str，在输入要删去的字符'd'。

运行结果:</p>
<pre>
$ gcc file1.c file2.c file3.c 
$ ./a.out
abcdef                   # 输入的字符串
d                        # 要删除的字符
abcef                    # 删除后的字符串
</pre>
<div class="comt-meta wrapper"><span class="comt-author"><a target="_blank" href="javascript:;">Sad</a><div class="tooltip tooltip1"><p><i class="fa fa-user" aria-hidden="true"></i>&nbsp;&nbsp;&nbsp;Sad</p><p><i class="fa fa-envelope" aria-hidden="true"></i>&nbsp;&nbsp;347***568@qq.com</p></div></span>6年前 (2017-03-20)</div></div></li><!-- #comment-## -->
<li class="comment odd alt thread-odd thread-alt depth-1" id="comment-18083"><span class="comt-f">#0</span><div class="comt-avatar wrapper"><i style="font-size:36px;" class="fa fa-user-circle" aria-hidden="true"></i><div class="tooltip"><p><i class="fa fa-user" aria-hidden="true"></i>&nbsp;&nbsp;&nbsp;月影困</p><p><i class="fa fa-envelope" aria-hidden="true"></i>&nbsp;&nbsp;cad***20601@163.com</p></div><div id="runoobvote-id-18083" data-commid = "18083" class="upvotejs"><a class="upvote"></a> <span class="count">85</span></div></div><div class="comt-main" id="div-comment-18083"><p><strong>内联函数</strong></p><p>内联函数是指用inline关键字修饰的函数。在类内定义的函数被默认成内联函数。内联函数从源代码层看，有函数的结构，而在编译后，却不具备函数的性质。</p><p>内联扩展是用来<strong>消除函数调用</strong><strong>时的时间开销</strong>。它通常用于频繁执行的函数，对于小内存空间的函数非常受益。</p><p>使用内联函数的时候要注意：</p><ul><li>递归函数不能定义为内联函数</li></ul><ul><li>内联函数一般适合于不存在while和switch等复杂的结构且只有1~5条语句的小函数上，否则编译系统将该函数视为普通函数。</li></ul><ul><li>内联函数只能先定义后使用，否则编译系统也会把它认为是普通函数。</li></ul><ul><li>对内联函数不能进行异常的接口声明。</li></ul><p></p><p><strong>示例：</strong>一个简单的交换函数</p>


<pre>inline void swap(int *a, int *b)
{
    int t = *a;
    *a = *b;
    *b = t;
}</pre><div class="comt-meta wrapper"><span class="comt-author"><a target="_blank" href="javascript:;">月影困</a><div class="tooltip tooltip1"><p><i class="fa fa-user" aria-hidden="true"></i>&nbsp;&nbsp;&nbsp;月影困</p><p><i class="fa fa-envelope" aria-hidden="true"></i>&nbsp;&nbsp;cad***20601@163.com</p></div></span>6年前 (2017-09-25)</div></div></li><!-- #comment-## -->
<li class="comment even thread-even depth-1" id="comment-19195"><span class="comt-f">#0</span><div class="comt-avatar wrapper"><i style="font-size:36px;" class="fa fa-user-circle" aria-hidden="true"></i><div class="tooltip"><p><i class="fa fa-user" aria-hidden="true"></i>&nbsp;&nbsp;&nbsp;ccf</p><p><i class="fa fa-envelope" aria-hidden="true"></i>&nbsp;&nbsp;130***0664@qq.com</p></div><div id="runoobvote-id-19195" data-commid = "19195" class="upvotejs"><a class="upvote"></a> <span class="count">134</span></div></div><div class="comt-main" id="div-comment-19195"><p><strong>关于 main 函数的参数</strong></p>
<p>在有些很专业的书会看到如下代码</p>

<pre>int main( int argc, char *argv[] )</pre>

<p>上面的代码中 main 函数带了参数。</p>

<p>但是有时又会看见main函数没有参数，如下：</p>

<pre>int main()</pre>

<p><strong>那么 main 函数到底有没有参数，有没有参数会不会有什么影响？</strong></p>

<p>main 函数其实与我们写的函数没有什么区别，它也会有自己的参数。</p>

<p>argc 和 argv 是 main 函数的形式参数。</p>

<p>这两个形式参数的类型是系统规定的。如果 main 函数要带参数，就是这两个类型的参数；否则main函数就没有参数。</p>

<p>变量名称argc和argv是常规的名称，当然也可以换成其他名称。在传入参数后main函数收到参数后就会做自己的事。那么，实际参数是如何传递给main函数的argc和argv的呢？我们知道，C程序在编译和链接后，都生成一个exe文件，执行该exe文件时，可以直接执行；也可以在命令行下带参数执行，命令行执行的形式为：可执行文件名称 参数1 参数2 ... ... 参数n。可执行文件名称和参数、参数之间均使用空格隔开。</p>

<p>如果按照这种方法执行，命令行字符串将作为实际参数传递给main函数。具体为：</p>
<ul><li>
(1) 可执行文件名称和所有参数的个数之和传递给 argc；
</li><li>
(2) 可执行文件名称（包括路径名称）作为一个字符串，首地址被赋给 argv[0]，参数1也作为一个字符串，首地址被赋给 argv[1]，... ...依次类推。</li></ul><div class="comt-meta wrapper"><span class="comt-author"><a target="_blank" href="javascript:;">ccf</a><div class="tooltip tooltip1"><p><i class="fa fa-user" aria-hidden="true"></i>&nbsp;&nbsp;&nbsp;ccf</p><p><i class="fa fa-envelope" aria-hidden="true"></i>&nbsp;&nbsp;130***0664@qq.com</p></div></span>6年前 (2017-10-21)</div></div></li><!-- #comment-## -->
<li class="comment odd alt thread-odd thread-alt depth-1" id="comment-19207"><span class="comt-f">#0</span><div class="comt-avatar wrapper"><i style="font-size:36px;" class="fa fa-user-circle" aria-hidden="true"></i><div class="tooltip"><p><i class="fa fa-user" aria-hidden="true"></i>&nbsp;&nbsp;&nbsp;kevintcl</p><p><i class="fa fa-envelope" aria-hidden="true"></i>&nbsp;&nbsp;299***2513@qq.com</p></div><div id="runoobvote-id-19207" data-commid = "19207" class="upvotejs"><a class="upvote"></a> <span class="count">40</span></div></div><div class="comt-main" id="div-comment-19207"><p data-title="C 求三个数中的最大值" data-commid="46877">上面的是求两个数的最大值，我的是求三个数的最大值：</p>

<pre>#include &lt;stdio.h&gt; 

int DoMax(int a, int b, int c){
    int max=a;
    if(b&gt;max){
        max=b;
        if(c&gt;max){
            max=c;
        }
    } else {
        if(c&gt;max){
            max=c;
        }
    }
    return max;
}

int main(){
    int x, y, z, maxOne;
    printf("请输入三个数字（空格分隔）:");
    scanf("%d%d%d",&amp;x,&amp;y,&amp;z);
    maxOne=DoMax(x, y, z);
    printf("\n");
    printf("最大数为:%d; \n",maxOne);
    return 0;
}

</pre>
<div class="comt-meta wrapper"><span class="comt-author"><a target="_blank" href="../note/19207">kevintcl</a><div class="tooltip tooltip1"><p><i class="fa fa-user" aria-hidden="true"></i>&nbsp;&nbsp;&nbsp;kevintcl</p><p><i class="fa fa-envelope" aria-hidden="true"></i>&nbsp;&nbsp;299***2513@qq.com</p></div></span>6年前 (2017-10-21)</div></div></li><!-- #comment-## -->
<li class="comment even thread-even depth-1" id="comment-19984"><span class="comt-f">#0</span><div class="comt-avatar wrapper"><i style="font-size:36px;" class="fa fa-user-circle" aria-hidden="true"></i><div class="tooltip"><p><i class="fa fa-user" aria-hidden="true"></i>&nbsp;&nbsp;&nbsp;BeanShell</p><p><i class="fa fa-envelope" aria-hidden="true"></i>&nbsp;&nbsp;286***384@qq.com</p></div><div id="runoobvote-id-19984" data-commid = "19984" class="upvotejs"><a class="upvote"></a> <span class="count">96</span></div></div><div class="comt-main" id="div-comment-19984"><h2>函数参数传递常用的三种方式
</h2><p>
示例程序均以交换两个整数为例。
</p>

<p><strong>1. 值传递</strong></p>


<pre>#include &lt;stdio.h&gt;

void swap(int x, int y);
void swap(int x, int y)
{
    int temp;
    temp = x;
    x = y;
    y = temp;
}

int main( int argc, char *argv[] )
{
    int a = 5;
    int b = 10;
    swap(a, b); //调用交换函数
    printf("交换结果为 a = %d, b = %d\n",a,b);
    return 0;
}</pre>


<p>由于值传递是单向传递，传递过程中只是改变了形参的数值，并未改变实参的数值，因此并不会改变a和b原有的值。</p>

<p><strong>2. 指针传递</strong></p>


<pre>#include &lt;stdio.h&gt;

void swap(int *x, int *y);
void swap(int *x, int *y)
{
    int temp;
    temp = *x;
    *x = *y;
    *y = temp;
}

int main( int argc, char *argv[] )
{
    int a = 5;
    int b = 10;
    swap(&amp;a, &amp;b); //调用交换函数
    printf("交换结果为 a = %d, b = %d\n",a,b);
    return 0;
}</pre>


<p>指针传递过程中，将a和b的地址分别传递给了x和y，在函数体内部改变了a、b所在地址的值，即交换了a、b的数值。</p>

<p><strong>3. 引用传递</strong></p>


<pre>#include &lt;stdio.h&gt;

void swap(int &amp;x, int &amp;y);
void swap(int &amp;x, int &amp;y)
{
    int temp;
    temp = x;
    x = y;
    y = temp;
}

int main( int argc, char *argv[] )
{
    int a = 5;
    int b = 10;
    swap(a, b); //调用交换函数
    printf("交换结果为 a = %d, b = %d\n",a,b);
    return 0;
}</pre>


<p>引用传递中，在调用swap(a, b);时函数会用a、b分别代替x、y，即x、y分别引用了a、b变量，这样函数体中实际参与运算的其实就是实参a、b本身，因此也能达到交换数值的目的。</p>

<p><strong>注：</strong>严格来说，C语言中是没有引用传递，这是C++中语言特性，因此在.c文件中使用引用传递会导致程序编译出错。</p>

<div class="comt-meta wrapper"><span class="comt-author"><a target="_blank" href="javascript:;">BeanShell</a><div class="tooltip tooltip1"><p><i class="fa fa-user" aria-hidden="true"></i>&nbsp;&nbsp;&nbsp;BeanShell</p><p><i class="fa fa-envelope" aria-hidden="true"></i>&nbsp;&nbsp;286***384@qq.com</p></div></span>6年前 (2017-11-07)</div></div></li><!-- #comment-## -->
<li class="comment odd alt thread-odd thread-alt depth-1" id="comment-23397"><span class="comt-f">#0</span><div class="comt-avatar wrapper"><i style="font-size:36px;" class="fa fa-user-circle" aria-hidden="true"></i><div class="tooltip"><p><i class="fa fa-user" aria-hidden="true"></i>&nbsp;&nbsp;&nbsp;喵帕斯</p><p><i class="fa fa-envelope" aria-hidden="true"></i>&nbsp;&nbsp;115***2452@qq.com</p></div><div id="runoobvote-id-23397" data-commid = "23397" class="upvotejs"><a class="upvote"></a> <span class="count">40</span></div></div><div class="comt-main" id="div-comment-23397"><p>函数声明和函数原型的参数名可以不一样，编译器他想知道的是函数参数的类型，与函数参数的名字没有关系，eg:</p>

#<pre>include&lt;stdio.h&gt;

int sum(int c,int d); // 函数声明

int main(int argc ,char*argv[])
{
   int a=2,b=3;
   printf("输出结果为: %d \n",sum(a,b));
   return 0;
}

int sum(int a,int b)
{
    return a+b ;
}</pre>


<p>甚至函数声明可以写成:</p>

<pre>int sum(int ,int );</pre>

<p>编译器只要检查到函数返回类型，名称和参数类型正确即可。</p><div class="comt-meta wrapper"><span class="comt-author"><a target="_blank" href="javascript:;">喵帕斯</a><div class="tooltip tooltip1"><p><i class="fa fa-user" aria-hidden="true"></i>&nbsp;&nbsp;&nbsp;喵帕斯</p><p><i class="fa fa-envelope" aria-hidden="true"></i>&nbsp;&nbsp;115***2452@qq.com</p></div></span>5年前 (2018-01-23)</div></div></li><!-- #comment-## -->
<li class="comment even thread-even depth-1" id="comment-24134"><span class="comt-f">#0</span><div class="comt-avatar wrapper"><i style="font-size:36px;" class="fa fa-user-circle" aria-hidden="true"></i><div class="tooltip"><p><i class="fa fa-user" aria-hidden="true"></i>&nbsp;&nbsp;&nbsp;流浪天涯</p><p><i class="fa fa-envelope" aria-hidden="true"></i>&nbsp;&nbsp;223***9389@qq.com</p></div><div id="runoobvote-id-24134" data-commid = "24134" class="upvotejs"><a class="upvote"></a> <span class="count">39</span></div></div><div class="comt-main" id="div-comment-24134"><p>函数实现了代码的重用，大大简化缩短了程序员的工作量，更使得程序的可读性大大提高，函数的递归调用更是一种简化程序代码的方法；递归调用其实机是函数自己调用自己。</p>
<p>下面的实例是一个求1+2+3.....+n的递归实例：</p>
<pre>#include &lt;stdio.h&gt;  //导如输入输出头文件

int sum(int n);//声明函数 
int main(){
    //主函数 
    int a=sum(4);
    printf("%d",a);
  return 0;
}
int sum(int n){
    //求和函数实现 
    //如果n为1，无需求和，直接返回1 
    if(n==1){
        return 1;
    }
    //如果n大于1，就返回n加上1+2+3.....+n-1的和 
    return n+sum(n-1);
}</pre>
<p>可以发现，递归的代码很少，但是，递归也有缺点，递归占用的内存要比递推大，而且时间也要比递推长。</p><div class="comt-meta wrapper"><span class="comt-author"><a target="_blank" href="javascript:;">流浪天涯</a><div class="tooltip tooltip1"><p><i class="fa fa-user" aria-hidden="true"></i>&nbsp;&nbsp;&nbsp;流浪天涯</p><p><i class="fa fa-envelope" aria-hidden="true"></i>&nbsp;&nbsp;223***9389@qq.com</p></div></span>5年前 (2018-02-12)</div></div></li><!-- #comment-## -->
<li class="comment odd alt thread-odd thread-alt depth-1" id="comment-26809"><span class="comt-f">#0</span><div class="comt-avatar wrapper"><i style="font-size:36px;" class="fa fa-user-circle" aria-hidden="true"></i><div class="tooltip"><p><i class="fa fa-user" aria-hidden="true"></i>&nbsp;&nbsp;&nbsp;Helen</p><p><i class="fa fa-envelope" aria-hidden="true"></i>&nbsp;&nbsp;QQ9***13813@163.com</p><p><i class="fa fa-external-link" aria-hidden="true"></i> <a rel="nofollow" target="_blank" href="https://baike.baidu.com/item/%E5%8D%A0%E4%BD%8D%E7%AC%A6/2953854">&nbsp;&nbsp;参考地址</a></p></div><div id="runoobvote-id-26809" data-commid = "26809" class="upvotejs"><a class="upvote"></a> <span class="count">104</span></div></div><div class="comt-main" id="div-comment-26809"><p data-title="C/C++ 占位符">占位符就是先占住一个固定的位置，等着你再往里面添加内容的符号，广泛用于计算机中各类文档的编辑。</p>

<p>格式占位符(%)是在C/C++语言中格式输入函数，如 scanf、printf 等函数中使用。其意义就是起到格式占位的意思，表示在该位置有输入或者输出。</p>

<ul><li>
<span class="marked">%d, %i</span> 代表整数</li><li>
<span class="marked">%f</span> 浮点</li><li>
<span class="marked">%s</span> 字符串</li><li>
<span class="marked">%c</span> char</li><li>
<span class="marked">%p</span> 指针</li><li>
<span class="marked">%fL</span> 长log</li><li>
<span class="marked">%e</span> 科学计数</li><li>
<span class="marked">%g</span> 小数或科学计数。

</li>
<li>
<span class="marked">%a,%A</span> 读入一个浮点值(仅C99有效)。
</li><li>
<span class="marked">%c</span> 读入一个字符。
</li><li>
<span class="marked">%d</span> 读入十进制整数。
</li><li>
<span class="marked">%i</span> 读入十进制，八进制，十六进制整数。
</li><li>
<span class="marked">%o</span> 读入八进制整数。
</li><li>
<span class="marked">%x,%X</span> 读入十六进制整数。
</li><li>
<span class="marked">%s</span> 读入一个字符串，遇空格、制表符或换行符结束。
</li><li>
<span class="marked">%f,%F,%e,%E,%g,%G</span> 用来输入实数，可以用小数形式或指数形式输入。
</li><li>
<span class="marked">%p</span> 读入一个指针。
</li><li>
<span class="marked">%u </span>读入一个无符号十进制整数。
</li><li>
<span class="marked">%n</span> 至此已读入值的等价字符数。
</li><li>
<span class="marked">%[]</span> 扫描字符集合。
</li><li>
<span class="marked">%%</span> 读 % 符号</li></ul>

<p><strong>实例：</strong></p>
<pre>scanf("%d,%d,%d",&amp;a,&amp;b,&amp;c); // 从键盘输入三个整数，用逗号分隔 　
scanf("%c", &amp;s);   // 从键盘输入一个字符 　
scanf("%f", &amp;f);   // 从键盘输入一个浮点型数据 　
printf("%d\n",a);  // 输出一个整数 　
printf("%f\n",b);  // 输出一个浮点数 　
printf("%s\n",c);  // 输出一个字符, 其中\n表示换行</pre><div class="comt-meta wrapper"><span class="comt-author"><a target="_blank" href="../note/26809">Helen</a><div class="tooltip tooltip1"><p><i class="fa fa-user" aria-hidden="true"></i>&nbsp;&nbsp;&nbsp;Helen</p><p><i class="fa fa-envelope" aria-hidden="true"></i>&nbsp;&nbsp;QQ9***13813@163.com</p><p><i class="fa fa-external-link" aria-hidden="true"></i> <a rel="nofollow" target="_blank" href="https://baike.baidu.com/item/%E5%8D%A0%E4%BD%8D%E7%AC%A6/2953854">&nbsp;&nbsp;参考地址</a></p></div></span>5年前 (2018-04-30)</div></div></li><!-- #comment-## -->
<li class="comment even thread-even depth-1" id="comment-37073"><span class="comt-f">#0</span><div class="comt-avatar wrapper"><i style="font-size:36px;" class="fa fa-user-circle" aria-hidden="true"></i><div class="tooltip"><p><i class="fa fa-user" aria-hidden="true"></i>&nbsp;&nbsp;&nbsp;金刚大魔王</p><p><i class="fa fa-envelope" aria-hidden="true"></i>&nbsp;&nbsp;285***3993@qq.com</p></div><div id="runoobvote-id-37073" data-commid = "37073" class="upvotejs"><a class="upvote"></a> <span class="count">58</span></div></div><div class="comt-main" id="div-comment-37073"><p><strong>1、函数的调用</strong>：由于程序是从上向下执行，所以函数要先声明，后调用。这种先后是文档中所处位置的先后，不是时间的先后。以下写法为正确的：</p>
<pre>#include&lt;stdio.h&gt;

void f(void)  /*定义函数*/
{
    printf("我是一个函数，我将在主函数中输出\n");
}

int main(void)
{
    f();  /*调用函数*/
}</pre>

<p>在上面这个实例中，在主函数中调用了函数 <strong>f()</strong>, 而函数的声明是在调用以前。</p>

<p>2、这种写法是错误的</p>

<pre>#include&lt;stdio.h&gt;

int main(void)
{
    f();/*调用函数*/
}

void f(void)  /*定义函数*/
{
    printf("我是一个函数，我将在主函数中输出\n");
}</pre>

<p>在上面这个实例中，在主函数中调用了函数<strong> f()</strong>, 而函数的声明却在调用之后。由于函数执行时是从上往下执行的所以，这写法是错误的。</p>

<p>如果函数非要写在主函数之后可以在主函数之前加入一个函数的前置声明。</p>

<p>前置声明如下：</p>

<pre>#include&lt;stdio.h&gt;

void f(void); /*前置声明*/
int main(void)  
{
    f();  /*调用函数*/
}

void f(void)  /*定义函数*/
{
    printf("我是一个函数，我一定要先声明后调用\n");
}</pre><div class="comt-meta wrapper"><span class="comt-author"><a target="_blank" href="javascript:;">金刚大魔王</a><div class="tooltip tooltip1"><p><i class="fa fa-user" aria-hidden="true"></i>&nbsp;&nbsp;&nbsp;金刚大魔王</p><p><i class="fa fa-envelope" aria-hidden="true"></i>&nbsp;&nbsp;285***3993@qq.com</p></div></span>5年前 (2018-11-17)</div></div></li><!-- #comment-## -->
<li class="comment odd alt thread-odd thread-alt depth-1" id="comment-46614"><span class="comt-f">#0</span><div class="comt-avatar wrapper"><i style="font-size:36px;" class="fa fa-user-circle" aria-hidden="true"></i><div class="tooltip"><p><i class="fa fa-user" aria-hidden="true"></i>&nbsp;&nbsp;&nbsp;朝阳</p><p><i class="fa fa-envelope" aria-hidden="true"></i>&nbsp;&nbsp;120***3522@qq.com</p></div><div id="runoobvote-id-46614" data-commid = "46614" class="upvotejs"><a class="upvote"></a> <span class="count">46</span></div></div><div class="comt-main" id="div-comment-46614"><p>本质上说，C 里面所有的函数参数传递，都是值传递。</p>

<p>指针传递之所以能改变传递参数变量的值，是因为 swap 函数交换的不是传递进来的指针本身，而是指针指向的值。</p>

<pre>void swap(int *x, int *y);
void swap(int *x, int *y){
    int temp;
    //这里操作的是指针指向的值 而不是指针
    temp = *x;
    *x = *y;
    *y = temp;
//   倘若直接交换指针 a、b的值不会交换
//    temp = x;
//    x = y;
//    y = temp;
}

int main( int argc, char *argv[] )
{
    int a = 5;
    int b = 10;
    swap(&amp;a, &amp;b); //调用交换函数
    printf("交换结果为 a = %d, b = %d\n",a,b);
    return 0;
}</pre>
<p>引用传递也类似。</p><div class="comt-meta wrapper"><span class="comt-author"><a target="_blank" href="javascript:;">朝阳</a><div class="tooltip tooltip1"><p><i class="fa fa-user" aria-hidden="true"></i>&nbsp;&nbsp;&nbsp;朝阳</p><p><i class="fa fa-envelope" aria-hidden="true"></i>&nbsp;&nbsp;120***3522@qq.com</p></div></span>4年前 (2019-09-10)</div></div></li><!-- #comment-## -->
<li class="comment even thread-even depth-1" id="comment-46877"><span class="comt-f">#0</span><div class="comt-avatar wrapper"><i style="font-size:36px;" class="fa fa-user-circle" aria-hidden="true"></i><div class="tooltip"><p><i class="fa fa-user" aria-hidden="true"></i>&nbsp;&nbsp;&nbsp;刘一米</p><p><i class="fa fa-envelope" aria-hidden="true"></i>&nbsp;&nbsp;liu***1007@126.com</p></div><div id="runoobvote-id-46877" data-commid = "46877" class="upvotejs"><a class="upvote"></a> <span class="count">42</span></div></div><div class="comt-main" id="div-comment-46877"><p>上面那个3个数最大值的太复杂，我这个好理解些:</p>

<pre>
#include &lt;stdio.h&gt;

int main()
{
   int a,b,c,max;
   printf("请输入三个数字（空格分隔）:");
   scanf("%d%d%d",&amp;a,&amp;b,&amp;c);
   if(a==b==c) 
      max=a;
   else if((a&gt;b)&amp;&amp;(a&gt;c))
      max=a;
   else if((b&gt;a)&amp;&amp;(b&gt;c))
      max=b;
   else if((c&gt;a)&amp;&amp;(c&gt;a))
      max=c;
   printf("max=%d",max);
   return 0;
}
</pre><div class="comt-meta wrapper"><span class="comt-author"><a target="_blank" href="javascript:;">刘一米</a><div class="tooltip tooltip1"><p><i class="fa fa-user" aria-hidden="true"></i>&nbsp;&nbsp;&nbsp;刘一米</p><p><i class="fa fa-envelope" aria-hidden="true"></i>&nbsp;&nbsp;liu***1007@126.com</p></div></span>4年前 (2019-09-19)</div></div></li><!-- #comment-## -->
<li class="comment odd alt thread-odd thread-alt depth-1" id="comment-48586"><span class="comt-f">#0</span><div class="comt-avatar wrapper"><i style="font-size:36px;" class="fa fa-user-circle" aria-hidden="true"></i><div class="tooltip"><p><i class="fa fa-user" aria-hidden="true"></i>&nbsp;&nbsp;&nbsp;罗小白</p><p><i class="fa fa-envelope" aria-hidden="true"></i>&nbsp;&nbsp;195***8404@qq.com</p></div><div id="runoobvote-id-48586" data-commid = "48586" class="upvotejs"><a class="upvote"></a> <span class="count">94</span></div></div><div class="comt-main" id="div-comment-48586"><p>上面求3个数最大值的太复杂，这个更简洁：</p>

<pre>#include &lt;stdio.h&gt;

float myMax(float a, float b, float c){
  return a&gt;=b ? (a&gt;=c ? a : c) : (b&gt;=c ? b : c);
}

int main() {
    float x, y, z, maxValue;
    printf("请输入任意三个数：\n");
    scanf("%f%f%f", &amp;x,&amp;y,&amp;z);
    maxValue = myMax(x, y, z);
    printf("最大值为：%f\n", maxValue);

    return 0;
}</pre><div class="comt-meta wrapper"><span class="comt-author"><a target="_blank" href="javascript:;">罗小白</a><div class="tooltip tooltip1"><p><i class="fa fa-user" aria-hidden="true"></i>&nbsp;&nbsp;&nbsp;罗小白</p><p><i class="fa fa-envelope" aria-hidden="true"></i>&nbsp;&nbsp;195***8404@qq.com</p></div></span>3年前 (2019-11-19)</div></div></li><!-- #comment-## -->
<li class="comment even thread-even depth-1" id="comment-49119"><span class="comt-f">#0</span><div class="comt-avatar wrapper"><i style="font-size:36px;" class="fa fa-user-circle" aria-hidden="true"></i><div class="tooltip"><p><i class="fa fa-user" aria-hidden="true"></i>&nbsp;&nbsp;&nbsp;hft</p><p><i class="fa fa-envelope" aria-hidden="true"></i>&nbsp;&nbsp;hou***ao@sjtu.edu.cn</p></div><div id="runoobvote-id-49119" data-commid = "49119" class="upvotejs"><a class="upvote"></a> <span class="count">22</span></div></div><div class="comt-main" id="div-comment-49119"><p><strong>“本质上说，C 里面所有的函数参数传递，都是值传递”</strong>，这一条，完全正确的代码如下：</p>

<pre>#include&lt;stdio.h&gt;

void swap(int *x, int *y);

void swap(int *x, int *y)
{
    int temp;
    temp = *x;
    *x = *y;
    *y = temp;
}

int main()
{
    int a = 5;
    int b = 10;
    swap(&amp;a, &amp;b);
    printf("result of swap: a=%d, b=%d", a, b);
    return 0;
}</pre><div class="comt-meta wrapper"><span class="comt-author"><a target="_blank" href="javascript:;">hft</a><div class="tooltip tooltip1"><p><i class="fa fa-user" aria-hidden="true"></i>&nbsp;&nbsp;&nbsp;hft</p><p><i class="fa fa-envelope" aria-hidden="true"></i>&nbsp;&nbsp;hou***ao@sjtu.edu.cn</p></div></span>3年前 (2019-12-08)</div></div></li><!-- #comment-## -->
<li class="comment odd alt thread-odd thread-alt depth-1" id="comment-50289"><span class="comt-f">#0</span><div class="comt-avatar wrapper"><i style="font-size:36px;" class="fa fa-user-circle" aria-hidden="true"></i><div class="tooltip"><p><i class="fa fa-user" aria-hidden="true"></i>&nbsp;&nbsp;&nbsp;Shepherd R.</p><p><i class="fa fa-envelope" aria-hidden="true"></i>&nbsp;&nbsp;191***9938@qq.com</p></div><div id="runoobvote-id-50289" data-commid = "50289" class="upvotejs"><a class="upvote"></a> <span class="count">22</span></div></div><div class="comt-main" id="div-comment-50289"><p>函数名和参数列表一起构成了函数签名。意味着可以出现参数列表不同但是函数名相同的函数。比如说定义两个函数：</p>

<pre>void print()
{
    printf("hello world!");
}

void print(int nums)
{
    printf("%d\n",a);
}</pre>
<p>
这是合法的。</p><div class="comt-meta wrapper"><span class="comt-author"><a target="_blank" href="javascript:;">Shepherd R.</a><div class="tooltip tooltip1"><p><i class="fa fa-user" aria-hidden="true"></i>&nbsp;&nbsp;&nbsp;Shepherd R.</p><p><i class="fa fa-envelope" aria-hidden="true"></i>&nbsp;&nbsp;191***9938@qq.com</p></div></span>3年前 (2020-01-26)</div></div></li><!-- #comment-## -->
<li class="comment even thread-even depth-1" id="comment-65069"><span class="comt-f">#0</span><div class="comt-avatar wrapper"><i style="font-size:36px;" class="fa fa-user-circle" aria-hidden="true"></i><div class="tooltip"><p><i class="fa fa-user" aria-hidden="true"></i>&nbsp;&nbsp;&nbsp;lyonmu</p><p><i class="fa fa-envelope" aria-hidden="true"></i>&nbsp;&nbsp;muq***cloud@gmail.com</p><p><i class="fa fa-external-link" aria-hidden="true"></i> <a rel="nofollow" target="_blank" href="https://www.dotcpp.com/course/43">&nbsp;&nbsp;参考地址</a></p></div><div id="runoobvote-id-65069" data-commid = "65069" class="upvotejs"><a class="upvote"></a> <span class="count">30</span></div></div><div class="comt-main" id="div-comment-65069"><p>可以用预处理命令 define 来定义简单函数：</p>

<pre>#define  MAX_3(a, b, c) ( ((a &gt; b ? a : b) &gt; c) ? (a &gt; b ? a : b) : c )
#define  MIN_3(a, b, c) ( ((a &lt; b ? a : b) &lt; c) ? (a &lt; b ? a : b) : c )
#define  MAX_2(x, y)  ( x&gt; y ? x : y )
#define  MIN_2(x, y)  ( x&lt; y ? x : y )
#define  ARR_SIZE(a)  ( sizeof( (a) ) / sizeof( (a[0]) ) )
#define  MULTIPLE(m, n) ( (m%n == 0)?0:1 )
#define  AVE_3(a, b, c) (a+b+c)/3
#define  SUM_3(a, b, c) a+b+c
#define  SWAP(a, b){int t= a;a=b;b=t;}</pre><div class="comt-meta wrapper"><span class="comt-author"><a target="_blank" href="javascript:;">lyonmu</a><div class="tooltip tooltip1"><p><i class="fa fa-user" aria-hidden="true"></i>&nbsp;&nbsp;&nbsp;lyonmu</p><p><i class="fa fa-envelope" aria-hidden="true"></i>&nbsp;&nbsp;muq***cloud@gmail.com</p><p><i class="fa fa-external-link" aria-hidden="true"></i> <a rel="nofollow" target="_blank" href="https://www.dotcpp.com/course/43">&nbsp;&nbsp;参考地址</a></p></div></span>2年前 (2021-07-09)</div></div></li><!-- #comment-## -->
	</ol>
	<div class="pagenav">
			</div>
</div>
<div id="respond" class="no_webshot"> 
		<div class="comment-signarea" style="display:none; padding: 20px 20px;"> 
	<h3 class="text-muted" id="share_code" style="color: #799961;"><i class="fa fa-pencil-square-o" aria-hidden="true"></i> 点我分享笔记</h3>
	<!--
	<p style="font-size:14px;">笔记需要是本篇文章的内容扩展！</p><br>
	<p style="font-size:12px;"><a href="../tougao" target="_blank">文章投稿，可点击这里</a></p>
	<p style="font-size:14px;"><a href="../w3cnote/runoob-user-test-intro.html#invite" target="_blank">注册邀请码获取方式</a></p>
		<h3 class="text-muted"><i class="fa fa-info-circle" aria-hidden="true"></i> 分享笔记前必须<a href="javascript:;" class="runoob-pop">登录</a>！</h3>
		<p><a href="../w3cnote/runoob-user-test-intro.html#invite" target="_blank">注册邀请码获取方式</a></p>-->
	</div>
		
	<form action="/wp-content/themes/runoob/option/addnote.php" method="post" id="commentform" style="display:none;">
		<div class="comt">
			<div class="comt-title">
				<i style="font-size:36px;" class="fa fa-user-circle" aria-hidden="true"></i>				<p><a id="cancel-comment-reply-link" href="javascript:;">取消</a></p>
			</div>
			<div class="comt-box">
			<div id="mded"></div>
			
				<div class="comt-ctrl">
					<div class="comt-tips"><input type='hidden' name='comment_post_ID' value='9513' id='comment_post_ID' />
<input type='hidden' name='comment_parent' id='comment_parent' value='0' />
</div>
					<button type="submit" name="submit" id="submit" tabindex="5"><i class="fa fa-pencil" aria-hidden="true"></i> 分享笔记</button>
				</div>
			</div>
		
				
					<div class="comt-comterinfo"> 
						<ul id="comment-author-info">
							<li class="form-inline"><label class="hide" for="author">昵称</label><input class="ipt" type="text" name="author" id="author" value="" tabindex="2" placeholder="昵称"><span class="text-muted">昵称 (必填)</span></li>
							<li class="form-inline"><label class="hide" for="email">邮箱</label><input class="ipt" type="text" name="email" id="email" value="" tabindex="3" placeholder="邮箱"><span class="text-muted">邮箱 (必填)</span></li>
							<li class="form-inline"><label class="hide" for="url">引用地址</label><input class="ipt" type="text" name="url" id="url" value="" tabindex="4" placeholder="引用地址"><span class="text-muted">引用地址</span></li>
						</ul>
					</div>
				
			
		</div>

	</form>
	</div>
<script type="text/javascript">
$(function() {
	//初始化编辑器
	
	var editor = new Simditor({
	  textarea: $('#mded'),
	  placeholder: '写笔记...',
	  upload:false,
	 // upload: {url:'/api/comment_upload_file.php',params: null,fileKey: 'upload_file',connectionCount: 1,leaveConfirm: '文件正在上传，您确定离开?'},
	  defaultImage: 'https://www.runoob.com/images/logo.png',
	  codeLanguages: '',
	  autosave: 'editor-content',
	  toolbar: [  'bold','code','ul','ol','image' ]
	});
	editor.on('selectionchanged', function() {
		$(".code-popover").hide();
	});

	// 提交数据
	$("#share_code").click(function() {
		$(".comment-signarea").hide();
		$("#commentform").show();
		
	});
	$("#user_add_note").click(function() {
		$(".comment-signarea").hide();
		$("#commentform").show();
		$('html, body').animate({
       	    scrollTop: $("#respond").offset().top
    	}, 200);
	});

	// 提交笔记
	var commentform=$('#commentform');
	commentform.prepend('<div id="comment-status" style="display:none;" ></div>');
	var statusdiv=$('#comment-status');
	
	commentform.submit(function(e){
		e.preventDefault();
		var noteContent = editor.getValue();
		// console.log(noteContent);
		noteContent = noteContent.replace(/<pre><code>/g,"<pre>");
		noteContent = noteContent.replace(/<\/code><\/pre>/g,"</pre>");
		
		// 系列化表单数据
		var comment_parent = 0;
		var is_user_logged_in = $("#is_user_logged_in").val();
		var comment_post_ID =  9513;
		var _wp_unfiltered_html_comment = $("#_wp_unfiltered_html_comment").val();
		var comment = noteContent;
		var author = $("#author").val();
		var url = $("#url").val();
		var email = $("#email").val();
		if(isBlank(author) && is_user_logged_in==0) {
			statusdiv.html('<p  class="ajax-error">请输入昵称！</p>').show();
		} else if(isBlank(email)  && is_user_logged_in==0) {
			statusdiv.html('<p  class="ajax-error">请输入邮箱！</p>').show();
		} else {
			// var formdata=commentform.serialize() + "&comment=" + noteContent ;
			// 添加状态信息
			statusdiv.html('<p>Processing...</p>').show();
			// 获取表单提交地址
			var formurl=commentform.attr('action');
			
			// 异步提交
			$.ajax({
					type: 'post',
					url: formurl,
					dataType:'json',
					data: {"comment_parent":comment_parent,"comment_post_ID":comment_post_ID, "_wp_unfiltered_html_comment":_wp_unfiltered_html_comment,"comment":comment,"url":url, "email":email,"author":author},
					error: function(XMLHttpRequest, textStatus, errorThrown){
					statusdiv.html('<p class="ajax-error" >数据不完整或表单提交太快了！</p>').show();
				},
				success: function(data, textStatus){
					if(data.errorno=="0") {
						$("#submit").prop('disabled', true);
						statusdiv.html('<p class="ajax-success" >笔记已提交审核，感谢分享笔记！</p>').show();
						alert('笔记已提交审核，感谢分享笔记！');
					}else{
						statusdiv.html('<p class="ajax-error" >'+data.msg+'</p>').show();
					}
					commentform.find('textarea[name=comment]').val('');
				}
			});
			setTimeout(function(){
		        $("#submit").prop('disabled', false);
		    }, 10*1000);
		}
		return false;

	});
	$(".comt-author").click(function() {
		href = $(this).children("a").attr("href");
		if(href.indexOf("/note/")!=-1) {
			var win = window.open(href, '_blank');
  			win.focus();
		}
	});
	$(".comt-meta span").hover(function(){
		$(this).children(".tooltip").css({ "opacity": 1, "pointer-events": "auto"});
	},function(){
		$(this).children(".tooltip").removeAttr("style");
	});
	/*
	$(".wrapper i").hover(function(){
		$(this).siblings(".tooltip").css({ "opacity": 1, "pointer-events": "auto"});
	},function(){
		$(this).siblings(".tooltip").css({ "opacity": 0, "pointer-events": "auto"});
	});
	*/
	//Upvote.create('runoobvote-id', {callback: vote_callback});
	var ajaxurl = 'https://www.runoob.com/wp-admin/admin-ajax.php';
	var callback = function(data) {
		//console.log($('#runoobvote-id').upvote('upvoted'));
		//console.log($('#runoobvote-id').upvote('downvoted'));
		//console.log(data);
		_vote_action = data.action;
		id_arr = data.id.split('-');
		um_id= id_arr[2];
		//console.log(um_id);
		
		var re = /^[1-9]+/;
		if (re.test(um_id)) { 
			var ajax_data = {
				_vote_action: _vote_action,
				action: "pinglun_zan",
				um_id: um_id,
				um_action: "ding"
			};
			//console.log(ajax_data);
			$.post(ajaxurl,ajax_data,function(status){
				//if(status.vote_num>999) {
				//	_voteHtml = '<span style="display: block; text-align: center;font-size: 20px; color: #6a737c; margin: 8px 0;">'+kFormatter(status.vote_num) +'</span>';
				//	$("#runoobvote-id-" + um_id + " .count").hide().after(_voteHtml);
				//}
				
			});
		}
	};
	if($('#comments').length && $('.upvotejs').length){
		$('.upvotejs').upvote({id: 9513, callback: callback});
	
		$.post(ajaxurl,{"action":"pinglun_zan","postid":9513},function(data){  
			$(data).each(function(key,value) {
				$("#runoobvote-id-" + value.commid + " .upvote").addClass(value.upvotejs_class);
				$("#runoobvote-id-" + value.commid + " .downvote").addClass(value.downvote_class);
				$("#runoobvote-id-" + value.commid + " .count").text(value.upvote_count);
			})
		},'json');
		
	}
	
	
});
function isBlank(str) {
    return (!str || /^\s*$/.test(str));
}
function kFormatter(num) {
	// return num;
    return Math.abs(num) > 999 ? Math.sign(num)*((Math.abs(num)/1000).toFixed(1)) + 'k' : Math.sign(num)*Math.abs(num)
}

</script>

<link rel="stylesheet" href="../0/qa.css?1.44">
<link rel="stylesheet" type="text/css" href="../0/simditor.min.css" />
<script type="text/javascript" src=""></script>
<script type="text/javascript" src=""></script>
<script type="text/javascript" src=""></script>
<script type="text/javascript" src=""></script>
<script type="text/javascript" src=""></script>
		<div class="sidebar-box ">
				

<style>	
.responsive_ad1 { display:none; }
@media(min-width: 800px) { .responsive_ad1 {  display:block;margin:0 auto;} }
</style>
<div id="ad-336280" >

<script async src=""
     crossorigin="anonymous"></script>
<!-- 移动版 自动调整 -->
<ins class="adsbygoogle"
     style="display:block"
     data-ad-client="ca-pub-5751451760833794"
     data-ad-slot="1691338467"
     data-ad-format="auto"
     data-full-width-responsive="true"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script>
		</div>
				</div>
		
	</div>
</div>
	

<!-- 右边栏 -->
<div class="fivecol last right-column">

<style>
.sidebar-tree .double-li {
    width:300px;
}
.sidebar-tree .double-li li {
    width: 44%;
    line-height: 1.5em;
    border-bottom: 1px solid #ccc;
    float: left;
    display: inline;
}
</style>

    
        <div class="sidebar-box re-box re-box-large">
        <div class="sidebar-box recommend-here" style="margin: 0 auto;">
            <a href="javascript:void(0);" style="font-size: 16px; color:#64854c;font-weight:bold;"> <i class="fa fa-list" aria-hidden="true"></i> 分类导航</a>
        </div>
    <div class="sidebar-box sidebar-cate">
        
        <div class="sidebar-tree" >
            <ul><li style="margin: 0;"><a href="javascript:void(0);" class="tit"> HTML / CSS</a><ul class="double-li"><li><a title="HTML 教程" href="../html/html-tutorial.html">HTML 教程</a></li><li><a title="HTML5 教程" href="../html/html5-intro.html">HTML5 教程</a></li><li><a title="CSS 教程" href="../css/css-tutorial.html">CSS 教程</a></li><li><a title="CSS3 教程" href="../css3/css3-tutorial.html">CSS3 教程</a></li><li><a title="Bootstrap3 教程" href="../bootstrap/bootstrap-tutorial.html">Bootstrap3 教程</a></li><li><a title="Bootstrap4 教程" href="../bootstrap4/bootstrap4-tutorial.html">Bootstrap4 教程</a></li><li><a title="Bootstrap5 教程" href="../bootstrap5/bootstrap5-tutorial.html">Bootstrap5 教程</a></li><li><a title="Font Awesome 教程" href="../font-awesome/fontawesome-tutorial.html">Font Awesome 教程</a></li><li><a title="Foundation 教程" href="../foundation/foundation-tutorial.html">Foundation 教程</a></li></ul></li><li style="margin: 0;"><a href="javascript:void(0);" class="tit"> JavaScript</a><ul class="double-li"><li><a title="JavaScript 教程" href="../js/js-tutorial.html">JavaScript 教程</a></li><li><a title="HTML DOM 教程" href="../htmldom/htmldom-tutorial.html">HTML DOM 教程</a></li><li><a title="jQuery 教程" href="../jquery/jquery-tutorial.html">jQuery 教程</a></li><li><a title="AngularJS 教程" href="../angularjs/angularjs-tutorial.html">AngularJS 教程</a></li><li><a title="AngularJS2 教程" href="../angularjs2/angularjs2-tutorial.html">AngularJS2 教程</a></li><li><a title="Vue.js 教程" href="../vue2/vue-tutorial.html">Vue.js 教程</a></li><li><a title="Vue3 教程" href="../vue3/vue3-tutorial.html">Vue3 教程</a></li><li><a title="React 教程" href="../react/react-tutorial.html">React 教程</a></li><li><a title="TypeScript 教程" href="../typescript/ts-tutorial.html">TypeScript 教程</a></li><li><a title="jQuery UI 教程" href="../jqueryui/jqueryui-tutorial.html">jQuery UI 教程</a></li><li><a title="jQuery EasyUI 教程" href="../jeasyui/jqueryeasyui-tutorial.html">jQuery EasyUI 教程</a></li><li><a title="Node.js 教程" href="../nodejs/nodejs-tutorial.html">Node.js 教程</a></li><li><a title="AJAX 教程" href="../ajax/ajax-tutorial.html">AJAX 教程</a></li><li><a title="JSON 教程" href="../json/json-tutorial.html">JSON 教程</a></li><li><a title="Echarts 教程" href="../echarts/echarts-tutorial.html">Echarts 教程</a></li><li><a title="Chart.js 教程" href="../chartjs/chartjs-tutorial.html">Chart.js 教程</a></li><li><a title="Highcharts 教程" href="../highcharts/highcharts-tutorial.html">Highcharts 教程</a></li><li><a title="Google 地图 教程" href="../googleapi/google-maps-basic.html">Google 地图 教程</a></li></ul></li><li style="margin: 0;"><a href="javascript:void(0);" class="tit"> 服务端</a><ul class="double-li"><li><a title="Python 教程" href="../python3/python3-tutorial.html">Python 教程</a></li><li><a title="Python2.x 教程" href="../python/python-tutorial.html">Python2.x 教程</a></li><li><a title="Linux 教程" href="../linux/linux-tutorial.html">Linux 教程</a></li><li><a title="Docker 教程" href="../docker/docker-tutorial.html">Docker 教程</a></li><li><a title="Ruby 教程" href="../ruby/ruby-tutorial.html">Ruby 教程</a></li><li><a title="Java 教程" href="../java/java-tutorial.html">Java 教程</a></li><li><a title="C 教程" href="../c/c-tutorial.html">C 教程</a></li><li><a title="C++ 教程" href="../cplusplus/cpp-tutorial.html">C++ 教程</a></li><li><a title="Perl 教程" href="../perl/perl-tutorial.html">Perl 教程</a></li><li><a title="Servlet 教程" href="../servlet/servlet-tutorial.html">Servlet 教程</a></li><li><a title="JSP 教程" href="../jsp/jsp-tutorial.html">JSP 教程</a></li><li><a title="Lua 教程" href="../lua/lua-tutorial.html">Lua 教程</a></li><li><a title="Rust 教程" href="../rust/rust-tutorial.html">Rust 教程</a></li><li><a title="Scala 教程" href="../scala/scala-tutorial.html">Scala 教程</a></li><li><a title="Go 教程" href="../go/go-tutorial.html">Go 教程</a></li><li><a title="PHP 教程" href="../php/php-tutorial.html">PHP 教程</a></li><li><a title="数据结构与算法" href="../data-structures/data-structures-tutorial.html">数据结构与算法</a></li><li><a title="Django 教程" href="../django/django-tutorial.html">Django 教程</a></li><li><a title="Zookeeper 教程" href="../w3cnote/zookeeper-tutorial.html">Zookeeper 教程</a></li><li><a title="设计模式" href="../design-pattern/design-pattern-tutorial.html">设计模式</a></li><li><a title="正则表达式" href="../regexp/regexp-tutorial.html">正则表达式</a></li><li><a title="Maven 教程" href="../maven/maven-tutorial.html">Maven 教程</a></li><li><a title="Verilog 教程" href="../w3cnote/verilog-tutorial.html">Verilog 教程</a></li><li><a title="ASP 教程" href="../asp/asp-tutorial.html">ASP 教程</a></li><li><a title="AppML 教程" href="../appml/appml-tutorial.html">AppML 教程</a></li><li><a title="VBScript 教程" href="../vbscript/vbscript-tutorial.html">VBScript 教程</a></li></ul></li><li style="margin: 0;"><a href="javascript:void(0);" class="tit"> 数据库</a><ul class="double-li"><li><a title="SQL 教程" href="../sql/sql-tutorial.html">SQL 教程</a></li><li><a title="MySQL 教程" href="../mysql/mysql-tutorial.html">MySQL 教程</a></li><li><a title="PostgreSQL 教程" href="../postgresql/postgresql-tutorial.html">PostgreSQL 教程</a></li><li><a title="SQLite 教程" href="../sqlite/sqlite-tutorial.html">SQLite 教程</a></li><li><a title="MongoDB 教程" href="../mongodb/mongodb-tutorial.html">MongoDB 教程</a></li><li><a title="Redis 教程" href="../redis/redis-tutorial.html">Redis 教程</a></li><li><a title="Memcached 教程" href="../Memcached/Memcached-tutorial.html">Memcached 教程</a></li></ul></li><li style="margin: 0;"><a href="javascript:void(0);" class="tit"> 数据分析</a><ul class="double-li"><li><a title="Python 教程" href="../python3/python3-tutorial.html">Python 教程</a></li><li><a title="NumPy 教程" href="../numpy/numpy-tutorial.html">NumPy 教程</a></li><li><a title="Pandas 教程" href="../pandas/pandas-tutorial.html">Pandas 教程</a></li><li><a title="Matplotlib 教程" href="../matplotlib/matplotlib-tutorial.html">Matplotlib 教程</a></li><li><a title="Scipy 教程" href="../scipy/scipy-tutorial.html">Scipy 教程</a></li><li><a title="R 教程" href="../r/r-tutorial.html">R 教程</a></li><li><a title="Julia 教程" href="../julia/julia-tutorial.html">Julia 教程</a></li></ul></li><li style="margin: 0;"><a href="javascript:void(0);" class="tit"> 移动端</a><ul class="double-li"><li><a title="Android 教程" href="../w3cnote/android-tutorial-intro.html">Android 教程</a></li><li><a title="Swift 教程" href="../swift/swift-tutorial.html">Swift 教程</a></li><li><a title="jQuery Mobile 教程" href="../jquerymobile/jquerymobile-tutorial.html">jQuery Mobile 教程</a></li><li><a title="ionic 教程" href="../ionic/ionic-tutorial.html">ionic 教程</a></li><li><a title="Kotlin 教程" href="../kotlin/kotlin-tutorial.html">Kotlin 教程</a></li></ul></li><li style="margin: 0;"><a href="javascript:void(0);" class="tit"> XML 教程</a><ul class="double-li"><li><a title="XML 教程" href="../xml/xml-tutorial.html">XML 教程</a></li><li><a title="DTD 教程" href="../dtd/dtd-tutorial.html">DTD 教程</a></li><li><a title="XML DOM 教程" href="../dom/dom-tutorial.html">XML DOM 教程</a></li><li><a title="XSLT 教程" href="../xsl/xsl-tutorial.html">XSLT 教程</a></li><li><a title="XPath 教程" href="../xpath/xpath-tutorial.html">XPath 教程</a></li><li><a title="XQuery 教程" href="../xquery/xquery-tutorial.html">XQuery 教程</a></li><li><a title="XLink 教程" href="../xlink/xlink-tutorial.html">XLink 教程</a></li><li><a title="XPointer 教程" href="../xlink/xlink-tutorial.html">XPointer 教程</a></li><li><a title="XML Schema 教程" href="../schema/schema-tutorial.html">XML Schema 教程</a></li><li><a title="XSL-FO 教程" href="../xslfo/xslfo-tutorial.html">XSL-FO 教程</a></li><li><a title="SVG 教程" href="../svg/svg-tutorial.html">SVG 教程</a></li></ul></li><li style="margin: 0;"><a href="javascript:void(0);" class="tit"> ASP.NET</a><ul class="double-li"><li><a title="ASP.NET 教程" href="../aspnet/aspnet-tutorial.html">ASP.NET 教程</a></li><li><a title="C# 教程" href="../csharp/csharp-tutorial.html">C# 教程</a></li><li><a title="Web Pages 教程" href="../aspnet/webpages-intro.html">Web Pages 教程</a></li><li><a title="Razor 教程" href="../aspnet/razor-intro.html">Razor 教程</a></li><li><a title="MVC 教程" href="../aspnet/mvc-intro.html">MVC 教程</a></li><li><a title="Web Forms 教程" href="../aspnet/aspnet-intro.html">Web Forms 教程</a></li></ul></li><li style="margin: 0;"><a href="javascript:void(0);" class="tit"> Web Service</a><ul class="double-li"><li><a title="Web Service 教程" href="../webservices/webservices-tutorial.html">Web Service 教程</a></li><li><a title="WSDL 教程" href="../wsdl/wsdl-tutorial.html">WSDL 教程</a></li><li><a title="SOAP 教程" href="../soap/soap-tutorial.html">SOAP 教程</a></li><li><a title="RSS 教程" href="../rss/rss-tutorial.html">RSS 教程</a></li><li><a title="RDF 教程" href="../rdf/rdf-tutorial.html">RDF 教程</a></li></ul></li><li style="margin: 0;"><a href="javascript:void(0);" class="tit"> 开发工具</a><ul class="double-li"><li><a title="Eclipse 教程" href="../eclipse/eclipse-tutorial.html">Eclipse 教程</a></li><li><a title="Git 教程" href="../git/git-tutorial.html">Git 教程</a></li><li><a title="Svn 教程" href="../svn/svn-tutorial.html">Svn 教程</a></li><li><a title="Markdown 教程" href="../markdown/md-tutorial.html">Markdown 教程</a></li></ul></li><li style="margin: 0;"><a href="javascript:void(0);" class="tit"> 网站建设</a><ul class="double-li"><li><a title="HTTP 教程" href="../http/http-tutorial.html">HTTP 教程</a></li><li><a title="网站建设指南" href="../web/web-buildingprimer.html">网站建设指南</a></li><li><a title="浏览器信息" href="../browsers/browser-information.html">浏览器信息</a></li><li><a title="网站主机教程" href="../hosting/hosting-tutorial.html">网站主机教程</a></li><li><a title="TCP/IP 教程" href="../tcpip/tcpip-tutorial.html">TCP/IP 教程</a></li><li><a title="W3C 教程" href="../w3c/w3c-tutorial.html">W3C 教程</a></li><li><a title="网站品质" href="../quality/quality-tutorial.html">网站品质</a></li></ul></li></ul>            </div>
    
    </div>
    </div>
    <br>
    
    <div class="sidebar-box re-box re-box-large">
        <div class="sidebar-box recommend-here">
            <a href="javascript:void(0);">Advertisement</a>
        </div>
        <div class="re-600160" id="sidebar-right-re">
                <script async src=""></script>
        <!-- 侧栏1 -->
        <ins class="adsbygoogle"
             style="display:inline-block;width:160px;height:600px"
             data-ad-client="ca-pub-5751451760833794"
             data-ad-slot="4106274865"></ins>
        <script>
        (adsbygoogle = window.adsbygoogle || []).push({});
        </script>
                </div>
    </div>
</div></div>

</div>

<script>
var aid = 9513;
function coll() {
	$.post( '/wp-content/themes/runoob/option/user/userinfo.php', {aid:aid, action:"collarticle", opt:'add'},function( data ) {
		if(data.error==0) {
			$("#content").find("h1:first").find("a").attr("href","javascript:void(0);");
			$("#content").find("h1:first").find("img").attr("src","http://www.runoob.com/wp-content/themes/runoob/assets/img/coll2.png").css({width:32+"px",height:32+"px"});
		}
		alert(data.msg);
	},'json');
}
</script>


<!-- 反馈对话框开始 -->
<script src=""></script>
<link rel="stylesheet" href="../0/feedback.css?1.0" />
<script type="text/javascript">
$.feedback({
    ajaxURL: '/feedback/runoob_feedback.php',
	html2canvasURL: '/wp-content/themes/runoob/assets/feedback/stable/2.0/html2canvas.js',
	onClose: function () {
         window.location.reload();
    }
});
</script>
<!-- 反馈对话框结束 -->
<button class="feedback-btn feedback-btn-gray">反馈/建议</button>
<!-- 底部 -->
<div id="footer" class="mar-t50">
   <div class="runoob-block">
    <div class="runoob cf">
     <dl>
      <dt>
       在线实例
      </dt>
      <dd>
       &middot;<a target="_blank" href="../html/html-examples.html">HTML 实例</a>
      </dd>
      <dd>
       &middot;<a target="_blank" href="../css/css-examples.html">CSS 实例</a>
      </dd>
      <dd>
       &middot;<a target="_blank" href="../js/js-examples.html">JavaScript 实例</a>
      </dd>
      <dd>
       &middot;<a target="_blank" href="../ajx/ajax-examples.html">Ajax 实例</a>
      </dd>
       <dd>
       &middot;<a target="_blank" href="../jquery/jquery-examples.html">jQuery 实例</a>
      </dd>
      <dd>
       &middot;<a target="_blank" href="../xml/xml-examples.html">XML 实例</a>
      </dd>
      <dd>
       &middot;<a target="_blank" href="../java/java-examples.html">Java 实例</a>
      </dd>
     
     </dl>
     <dl>
      <dt>
      字符集&工具
      </dt>
      <dd>
       &middot; <a target="_blank" href="../charsets/html-charsets.html">HTML 字符集设置</a>
      </dd>
      <dd>
       &middot; <a target="_blank" href="../tags/html-ascii.html">HTML ASCII 字符集</a>
      </dd>
     <dd>
       &middot; <a target="_blank" href="https://c.runoob.com/front-end/6939/">JS 混淆/加密</a>
      </dd> 
      <dd>
       &middot; <a target="_blank" href="https://c.runoob.com/front-end/6232/">PNG/JPEG 图片压缩</a>
      </dd>
      <dd>
       &middot; <a target="_blank" href="../tags/html-colorpicker.html">HTML 拾色器</a>
      </dd>
      <dd>
       &middot; <a target="_blank" href="..//c.runoob.com/front-end/53">JSON 格式化工具</a>
      </dd>
      <dd>
       &middot; <a target="_blank" href="..//c.runoob.com/front-end/6680/">随机数生成器</a>
      </dd>
     </dl>
     <dl>
      <dt>
       最新更新
      </dt>
                   <dd>
       &middot;
      <a href="../matplotlib/matplotlib-imread.html" title="Matplotlib imread() 方法">Matplotlib imre...</a>
      </dd>
              <dd>
       &middot;
      <a href="../matplotlib/matplotlib-imsave.html" title="Matplotlib imsave() 方法">Matplotlib imsa...</a>
      </dd>
              <dd>
       &middot;
      <a href="../matplotlib/matplotlib-imshow.html" title="Matplotlib imshow() 方法">Matplotlib imsh...</a>
      </dd>
              <dd>
       &middot;
      <a href="../matplotlib/matplotlib-hist.html" title="Matplotlib 直方图">Matplotlib 直方图</a>
      </dd>
              <dd>
       &middot;
      <a href="../python3/python-func-object.html" title="Python object() 函数">Python object()...</a>
      </dd>
              <dd>
       &middot;
      <a href="../python3/python-ai-draw.html" title="Python AI 绘画">Python AI 绘画</a>
      </dd>
              <dd>
       &middot;
      <a href="../w3cnote/cursor-editor.html" title="神辅助 Cursor 编辑器，加入 GPT-4 让编码更轻松！">神辅助 Cursor ...</a>
      </dd>
             </dl>
     <dl>
      <dt>
       站点信息
      </dt>
      <dd>
       &middot;
       <a target="_blank" href="mailto:admin@runoob.com" rel="external nofollow">意见反馈</a>
       </dd>
      <dd>
       &middot;
      <a target="_blank" href="../disclaimer">免责声明</a>
       </dd>
      <dd>
       &middot;
       <a target="_blank" href="../aboutus">关于我们</a>
       </dd>
      <dd>
       &middot;
      <a target="_blank" href="../archives">文章归档</a>
      </dd>
    
     </dl>
    
     <div class="search-share">
      <div class="app-download">
        <div>
         <strong>关注微信</strong>
        </div>
      </div>
      <div class="share">
      <img width="128" height="128" src="/wp-content/themes/runoob/assets/images/qrcode.png" />
       </div>
     </div>
     
    </div>
   </div>
   <div class="w-1000 copyright">
     Copyright &copy; 2013-2023    <strong><a href="../" target="_blank">菜鸟教程</a></strong>&nbsp;
    <strong><a href="../" target="_blank">runoob.com</a></strong> All Rights Reserved. 备案号：<a target="_blank" rel="nofollow" href="https://beian.miit.gov.cn/">闽ICP备15012807号-1</a>
   </div>
  </div>
  <div class="fixed-btn">
    <a class="go-top" href="javascript:void(0)" title="返回顶部"> <i class="fa fa-angle-up"></i></a>
    <a class="qrcode"  href="javascript:void(0)" title="关注我们"><i class="fa fa-qrcode"></i></a>
    <a class="writer" style="display:none" href="javascript:void(0)"   title="标记/收藏"><i class="fa fa-star" aria-hidden="true"></i></a>
    <!-- qrcode modal -->
    <div id="bottom-qrcode" class="modal panel-modal hide fade in">
      <h4>微信关注</h4>
      <div class="panel-body"><img alt="微信关注" width="128" height="128" src="/wp-content/themes/runoob/assets/images/qrcode.png"></div> 
    </div>
  </div>

 <div style="display:none;">
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-84264393-2"></script>
<script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());

  gtag('config', 'UA-84264393-2');
</script>
<script>
var _hmt = _hmt || [];
(function() {
  var hm = document.createElement("script");
  hm.src = "https://hm.baidu.com/hm.js?3eec0b7da6548cf07db3bc477ea905ee";
  var s = document.getElementsByTagName("script")[0]; 
  s.parentNode.insertBefore(hm, s);
})();
</script>

</div>
<script>
window.jsui={
    www: 'https://www.runoob.com',
    uri: 'https://www.runoob.com/wp-content/themes/runoob'
};
</script>

<script src=""></script>
<script src=""></script>

</body>
</html>